<%-- 
    Document   : index
    Created on : 2016-6-28, 12:09:22
    Author     : 52461
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="../link.jsp"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="${base}/css/bootstrap-paper.css"/>
        <link rel="stylesheet" href="${base}/css/bootstrap-datetimepicker.min.css"/>
        <script type="text/javascript" src="${base}/js/dist/echarts-all.js" ></script>
         <script type="text/javascript" src="${base}/js/bootstrap-datetimepicker.min.js" ></script>
        <script type="text/javascript" src="${base}/js/bootstrap-datetimepicker.zh-CN.js" ></script>
        <title>统计</title>
    </head>
    <body ng-app="countApp" ng-controller="countCtrl">
        <ul class="nav nav-tabs" role="tablist">
            <li role="presentation" class="active"><a href="/demo/bootstrap3-plugin-tab.htm#home" aria-controls="home" role="tab" data-toggle="tab">设备工作量统计</a></li>
            <li role="presentation"><a href="/demo/bootstrap3-plugin-tab.htm#settings" aria-controls="settings" role="tab" data-toggle="tab">医生工作量统计</a></li>
            <li role="presentation"><a href="/demo/bootstrap3-plugin-tab.htm#rol" aria-controls="rol" role="tab" data-toggle="tab">病人统计</a></li>
        </ul>
        <div class="tab-content">
            <div role="tabpanel" class="tab-pane active" id="home">
                <div style="height:50px;width: 1000px;margin:0 auto;padding-top: 20px">
                    <span> 开始日期: <input type="text" id="startdevice" readonly></span>
                    <span> 结束日期: <input type="text" id="enddevice" readonly></span>
                </div>
                <div id="device" style="height:500px;width: 800px;margin:0 auto;padding-top: 20px"></div>
            </div>
            <div role="tabpanel" class="tab-pane" id="settings">
                <div style="height:50px;width: 1000px;margin:0 auto;padding-top: 20px">
                    <span>开始日期: <input type="text" id="startdoctor" readonly></span> 
                    <span>结束日期: <input type="text" id="enddoctor" readonly></span>
                </div>
                <div id="doctor" style="height:500px;width: 800px;margin:0 auto;padding-top: 20px"></div>
            </div>
            <div role="tabpanel" class="tab-pane" id="rol">
                <div style="height:50px;width: 1000px;margin:0 auto;padding-top: 20px">
                    <span>选择月份: <input type="text" id="patientdate" readonly></span> 
                </div>
                <div id="patient" style="height:500px;width: 800px;margin:0 auto;padding-top: 20px"></div>
            </div>
        </div>
        
        
    </body>
</html>
<script>
    angular.module("countApp", ['baseModule'])
    .controller("countCtrl", function ($scope,base) {
       
 //           **********************设备工作量数据结构*************************      
        $scope.devicename=[];
        $scope.deviceList=[];
             var deviceChart = echarts.init(document.getElementById('device')); 
             $scope.getDevice=function(){
                  $.ajax({
                      type:"post",
                      url:"count/getDeviceList",
                      async:false,
                      success:function(data){
                        $scope.deviceList=data;
                        
                        for(var i in data){
                            $scope.devicename.push(data[i].name);
                        }
                            deviceChart.setOption(device); 
                      }
                });
            }
            $scope.getDevice();
    device = {
    title : {
        text: '设备工作量统计',
        subtext: '',
        x:'center'
    },
    tooltip : {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    legend: {
        orient : 'vertical',
        x : 'left',
//        data:['血凝仪','mc-6600','ichenm-540','尿液化学分析仪','BC-2900']
        data:$scope.devicename
    },
    toolbox: {
        show : true,
        feature : {
            mark : {show: true},
            dataView : {show: true, readOnly: true},
            magicType : {
                show: true, 
                type: ['pie', 'funnel'],
                option: {
                    funnel: {
                        x: '25%',
                        width: '50%',
                        funnelAlign: 'left',
                        max: 100
                    }
                }
            },
            restore : {show: true},
            saveAsImage : {show: true}
        }
    },
    calculable : true,
    series : [
        {
            name:'设备型号',
            type:'pie',
            radius : '55%',
            center: ['50%', '60%'],
            data:$scope.deviceList
//            data:[
//                {value:335, name:'血凝仪'},
//                {value:310, name:'mc-6600'},
//                {value:234, name:'ichenm-540'},
//                {value:135, name:'尿液化学分析仪'},
//                {value:100, name:'BC-2900'}
//            ]
            }
        ]
    };
     
         $('#startdevice').datetimepicker({
                  language: 'zh-CN',
                  format: 'yyyy-mm-dd ',
                  startView: 3,
                  autoclose: true,
                  minView: 2
            }).on('changeDate', function (ev) {
                    $scope.startdate=ev.date.Format("yyyy-MM-dd");
            });     
             $('#enddevice').datetimepicker({
                  language: 'zh-CN',
                  format: 'yyyy-mm-dd ',
                  startView: 3,
                  autoclose: true,
                  minView: 2
                }).on('changeDate', function (ev) {
                    $scope.enddate=ev.date.Format("yyyy-MM-dd");
                    if($scope.startdate){
                        base.post("count/getDeviceDate",{start:$scope.startdate,end:$scope.enddate}).get(function(data){
                            if(data!="false"){
                                $scope.devicename.splice(0,$scope.devicename.length);
                                $scope.deviceList.splice(0,$scope.deviceList.length);
                                for(var i in data){
                                    $scope.devicename.push(data[i].name);
                                }
                                $scope.deviceList=data;
                                deviceChart.setOption(device); 
                            }else{
                                steveAl("没有数据", 1000);
                            }
                      });
                    }else{
                       steveAl("请选择开始日期", 1000);
                    }
                });     
//           **********************医生工作量数据结构*************************
            $scope.doctorname=[];
            $scope.doctorvalue=[];
            $scope.getDoctor=function(){
                  $.ajax({
                      type:"post",
                      url:"count/getDoctorList",
                      async:false,
                      success:function(data){
                        for(var i in data){
                            $scope.doctorname.push(data[i].name);
                            $scope.doctorvalue.push(data[i].value);
                        }
                      }
                });
            }
            $scope.getDoctor();
            var doctorChart = echarts.init(document.getElementById('doctor')); 
    doctor = {
                tooltip: {
                show: true
            },
            legend: {
                data:['工作量']
            },
            xAxis : [
                {
                    type : 'category',
//                    data : ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
                    data:$scope.doctorname
                }
            ],
            yAxis : [
                {
                    type : 'value'
                }
            ],
            series : [
                {
                    "name":"工作量",
                    "type":"bar",
//                    "data":[5, 20, 40, 10, 10, 20]
                     "data":$scope.doctorvalue
                }
            ]
        };
            doctorChart.setOption(doctor); 
            $('#startdoctor').datetimepicker({
                  language: 'zh-CN',
                  format: 'yyyy-mm-dd ',
                  startView: 3,
                  autoclose: true,
                  minView: 2
            }).on('changeDate', function (ev) {
                    $scope.startdodate=ev.date.Format("yyyy-MM-dd");
            });     
             $('#enddoctor').datetimepicker({
                  language: 'zh-CN',
                  format: 'yyyy-mm-dd ',
                  startView: 3,
                  autoclose: true,
                  minView: 2
                }).on('changeDate', function (ev) {
                    $scope.enddodate=ev.date.Format("yyyy-MM-dd");
                    if($scope.startdodate){
                        base.post("count/getDoctorDate",{start:$scope.startdodate,end:$scope.enddodate}).get(function(data){
                            if(data!="false"){
                                $scope.doctorname.splice(0,$scope.doctorname.length);
                                $scope.doctorvalue.splice(0,$scope.doctorvalue.length);
                                for(var i in data){
                                    $scope.doctorname.push(data[i].name);
                                    $scope.doctorvalue.push(data[i].value);
                                }
                                doctorChart.setOption(doctor); 
                            }else{
                                steveAl("没有数据", 1000);
                            }
                      });
                    }else{
                       steveAl("请选择开始日期", 1000);
                    }
                });
 
//           **********************病人统计数据结构*************************
            var patientChart = echarts.init(document.getElementById('patient'));
            $scope.patientCount=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
            $scope.sexCount=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
            $scope.dateCount=['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31'];
            $scope.sexNv=[];
            $scope.getPatientDay=function(){
                  $.ajax({
                      type:"post",
                      url:"count/getPatientToday",
                      async:false,
                      success:function(data){
                        for(var i in data){
                            var date = new Date(data[i].time);
                            var sqdate=date.getDate();
                            for(var j in $scope.dateCount){
                                if(sqdate==$scope.dateCount[j]){
                                    $scope.patientCount[j]=data[i].value;
                                }
                            }
//                           $scope.mothDay.push(date.getDate());
//                           $scope.patientCount.push(data[i].value);
                        }
                      }
                });
            }
            $scope.getPatientSex=function(){
                  $.ajax({
                      type:"post",
                      url:"count/getPatientSex",
                      async:false,
                      success:function(data){
                        for(var i in data){
                            var date = new Date(data[i].time);
                            var patday=date.getDate();
                            for(var j in $scope.dateCount){
                                if(patday==$scope.dateCount[j]){
                                    $scope.sexCount[j]=data[i].value;
                                }
                            }
                        }
                        
                      }
                });
            }
            $scope.getPatientSex();
            $scope.getPatientDay();
            
            $scope.countnv=function(){
                for(var i in $scope.patientCount){
                    var k=$scope.patientCount[i]-$scope.sexCount[i];
                    $scope.sexNv.push(k);
                }
            }
            $scope.countnv();
            patientOption = {
                title : {
                    text: '病人数量统计',
                    subtext: '数量'
                },
                tooltip : {
                    trigger: 'axis'
                },
                legend: {
                    data:['总数量','男','女']
                },
                toolbox: {
                    show : true,
                    feature : {
                        mark : {show: true},
                        dataView : {show: true, readOnly: true},
                        magicType : {show: true, type: ['line', 'bar']},
                        restore : {show: true},
                        saveAsImage : {show: true}
                    }
                },
                calculable : true,
                xAxis : [
                    {
                        type : 'category',
                        boundaryGap : false,
                        data : $scope.dateCount 
                                
                    }
                ],
                yAxis : [
                    {
                        type : 'value',
                        axisLabel : {
                            formatter: '{value}'
                        }
                    }
                ],
                series : [
                    {
                        name:'总数量',
                        type:'line',
                        data:$scope.patientCount,
                    },
                    {
                        name:'男',
                        type:'line',
                        data:$scope.sexCount,
                    },
                    {
                        name:'女',
                        type:'line',
                        data:$scope.sexNv,
                    }
                ]
            };
             patientChart.setOption(patientOption);    
            $('#patientdate').datetimepicker({
                  language: 'zh-CN',
                  format: 'yyyy-mm ',
                  startView: 3,
                  autoclose: true,
                  minView: 3
                }).on('changeDate', function (ev) {
                    var date=ev.date.Format("yyyy-MM");
                        base.post("count/getPatientMoth",{date:date}).get(function(data){
                            if(data!="false"){
                                $scope.patientCount=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
                                for(var i in data){
                                    var date = new Date(data[i].time);
                                    var sqdate=date.getDate();
                                    for(var j in $scope.dateCount){
                                        if(sqdate==$scope.dateCount[j]){
                                           $scope.patientCount[j]=data[i].value;
                                        }
                                    }
                                }
                                patientChart.setOption(patientOption); 
                            }else{
                                steveAl("没有数据", 1000);
                            }
                      });
                       base.post("count/getPatientSexDay",{date:date}).get(function(data){
                           $scope.sexCount=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
                           for(var i in data){
                            var date = new Date(data[i].time);
                            var patday=date.getDate();
                            for(var j in $scope.dateCount){
                                if(patday==$scope.dateCount[j]){
                                    $scope.sexCount[j]=data[i].value;
                                }
                            }
                        }
                       })
                             for(var i in $scope.patientCount){
                                var k=$scope.patientCount[i]-$scope.sexCount[i];
                                $scope.sexNv.push(k);
                            }
                        patientChart.setOption(patientOption); 
                });     
                        patientChart.setOption(patientOption); 
                
    })
</script>
